<!DOCTYPE html>
<!--
Copyright (c) 2015 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<link rel="import" href="/tracing/core/test_utils.html">
<link rel="import" href="/tracing/model/event_set.html">
<link rel="import" href="/tracing/model/global_memory_dump.html">
<link rel="import" href="/tracing/model/selection_state.html">
<link rel="import" href="/tracing/ui/timeline_viewport.html">
<link rel="import" href="/tracing/ui/tracks/alert_track.html">
<link rel="import" href="/tracing/ui/tracks/drawing_container.html">

<script>
'use strict';

tr.b.unittest.testSuite(function() {
  const AlertTrack = tr.ui.tracks.AlertTrack;
  const SelectionState = tr.model.SelectionState;
  const Viewport = tr.ui.TimelineViewport;

  const ALERT_INFO_1 = new tr.model.EventInfo(
      'Alert 1', 'One alert');
  const ALERT_INFO_2 = new tr.model.EventInfo(
      'Alert 2', 'Another alert');

  const createAlerts = function() {
    const alerts = [
      new tr.model.Alert(ALERT_INFO_1, 5),
      new tr.model.Alert(ALERT_INFO_1, 20),
      new tr.model.Alert(ALERT_INFO_2, 35),
      new tr.model.Alert(ALERT_INFO_2, 50)
    ];
    return alerts;
  };

  test('instantiate', function() {
    const alerts = createAlerts();
    alerts[1].selectionState = SelectionState.SELECTED;

    const div = document.createElement('div');
    const viewport = new Viewport(div);
    const drawingContainer = new tr.ui.tracks.DrawingContainer(viewport);
    Polymer.dom(div).appendChild(drawingContainer);

    const track = AlertTrack(viewport);
    Polymer.dom(drawingContainer).appendChild(track);

    this.addHTMLOutput(div);
    drawingContainer.invalidate();

    track.alerts = alerts;
    const dt = new tr.ui.TimelineDisplayTransform();
    dt.xSetWorldBounds(0, 50, track.clientWidth);
    track.viewport.setDisplayTransformImmediately(dt);


    assert.strictEqual(5, track.items[0].start);
  });

  test('modelMapping', function() {
    const alerts = createAlerts();

    const div = document.createElement('div');
    const viewport = new Viewport(div);
    const track = AlertTrack(viewport);
    track.alerts = alerts;

    const a0 = track.items[0].modelItem;
    assert.strictEqual(a0, alerts[0]);
  });
});
</script>

